// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using TestClient.Domain;
using TestClient.ViewModel.Util;

namespace TestClient.ViewModel;
public partial class ExportTestViewModel : PageViewModelBase
{
    [ObservableProperty]
    private string filepath = "";
    [ObservableProperty]
    private string filename = "test.stp";

    public IAsyncRelayCommand ExportStepCommand { get; }

    public ExportTestViewModel(VFAdapterWrapper wrapper, ISnackNotifyService notifyService) : base(wrapper, notifyService)
    {
        ExportStepCommand = CreateAsyncRpcCommand(ExportStep);
    }

    [RelayCommand]
    private void SelectFolder()
    {
        Filepath = DialogUtil.ShowOpenDirectoryDialog(Filepath) ?? Filepath;
    }

    private async Task ExportStep()
    {
        EnsureConnected();
        await Task.Run(() =>
        {
            Wrapper.SaveAsStep(Filename, Filepath);
        });
    }

}
